#!/usr/bin/node

const log = console.log;

const arg = process.argv[2];

//log(`arg:${arg}`);

if( typeof(arg) === 'undefined' || arg === '--help' || arg === '-h'){
  help();
}else{
  calc();
}

function calc(){
  try{
  //简易计算器
    log(`arg:${arg}`);
    log(`${arg}=${eval(arg)}`);
  }catch(e){
    console.error(`${arg}是非法的表达式`);
  }
}

function help(){
  const msg = 'usage:cmd-name [ OPTION ] [expression]\n evaluate the expression.\n Mandatory arguments to long options are mandatory for short options too.\n -h, --help output help information and exit\n ';

  log(msg);
}
